<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs">
<head>
<title>std::formatter</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../../common/favicon.ico">
<link rel="stylesheet" href="../../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-css:7:15cea3ec788a65b5187d4018eed543bf */</style>

<script src="../../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"cpp/utility/format/formatter","wgTitle":"cpp/utility/format/formatter","wgCurRevisionId":65265,"wgArticleId":12412,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Todo with reason"],"wgBreakFrames":false,"wgPageContentLanguage":"zh","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"zh","wgMonthNames":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgMonthNamesShort":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgRelevantPageName":"cpp/utility/format/formatter","wgUserVariant":"zh","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"zh","language":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-MathJax":1,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-js:7:258d7cd6aa9aa67dee25e01fb6a9e505 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-cpp {line-height: normal;}
.source-cpp li, .source-cpp pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for cpp
 * CSS class: source-cpp, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.cpp.source-cpp .de1, .cpp.source-cpp .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.cpp.source-cpp  {font-family:monospace;}
.cpp.source-cpp .imp {font-weight: bold; color: red;}
.cpp.source-cpp li, .cpp.source-cpp .li1 {font-weight: normal; vertical-align:top;}
.cpp.source-cpp .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.cpp.source-cpp .li2 {font-weight: bold; vertical-align:top;}
.cpp.source-cpp .kw1 {color: #0000dd;}
.cpp.source-cpp .kw2 {color: #0000ff;}
.cpp.source-cpp .kw3 {color: #0000dd;}
.cpp.source-cpp .kw4 {color: #0000ff;}
.cpp.source-cpp .co1 {color: #909090;}
.cpp.source-cpp .co2 {color: #339900;}
.cpp.source-cpp .coMULTI {color: #ff0000; font-style: italic;}
.cpp.source-cpp .es0 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es1 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es2 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es3 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es4 {color: #008000; font-weight: bold;}
.cpp.source-cpp .es5 {color: #008000; font-weight: bold;}
.cpp.source-cpp .br0 {color: #008000;}
.cpp.source-cpp .sy0 {color: #008000;}
.cpp.source-cpp .sy1 {color: #000080;}
.cpp.source-cpp .sy2 {color: #000040;}
.cpp.source-cpp .sy3 {color: #000040;}
.cpp.source-cpp .sy4 {color: #008080;}
.cpp.source-cpp .st0 {color: #008000;}
.cpp.source-cpp .nu0 {color: #000080;}
.cpp.source-cpp .nu6 {color: #000080;}
.cpp.source-cpp .nu8 {color: #000080;}
.cpp.source-cpp .nu12 {color: #000080;}
.cpp.source-cpp .nu16 {color:#000080;}
.cpp.source-cpp .nu17 {color:#000080;}
.cpp.source-cpp .nu18 {color:#000080;}
.cpp.source-cpp .nu19 {color:#000080;}
.cpp.source-cpp .ln-xtra, .cpp.source-cpp li.ln-xtra, .cpp.source-cpp div.ln-xtra {background-color: #ffc;}
.cpp.source-cpp span.xtra { display:block; }

/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal;}
.source-text li, .source-text pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for text
 * CSS class: source-text, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.text.source-text .de1, .text.source-text .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.text.source-text  {font-family:monospace;}
.text.source-text .imp {font-weight: bold; color: red;}
.text.source-text li, .text.source-text .li1 {font-weight: normal; vertical-align:top;}
.text.source-text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.text.source-text .li2 {font-weight: bold; vertical-align:top;}
.text.source-text .ln-xtra, .text.source-text li.ln-xtra, .text.source-text div.ln-xtra {background-color: #ffc;}
.text.source-text span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_utility_format_formatter skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::</span>formatter</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">来自cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../../cpp.html" title="cpp">cpp</a>‎ | <a href="../../utility.html" title="cpp/utility">utility</a>‎ | <a href="../format.html" title="cpp/utility/format">format</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../../cpp.html" title="cpp"> C++</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../../language.html" title="cpp/language">语言</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../header.html" title="cpp/header">标准库头文件</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../freestanding.html" title="cpp/freestanding"> 自立与有宿主实现</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../named_req.html" title="cpp/named req">具名要求</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../utility.html#.E8.AF.AD.E8.A8.80.E6.94.AF.E6.8C.81" title="cpp/utility">语言支持库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../concepts.html" title="cpp/concepts">概念库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../error.html" title="cpp/error">诊断库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../utility.html" title="cpp/utility">工具库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../string.html" title="cpp/string">字符串库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="https://zh.cppreference.com/w/cpp/container" title="cpp/container">容器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../iterator.html" title="cpp/iterator">迭代器库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../ranges.html" title="cpp/ranges"> 范围库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../algorithm.html" title="cpp/algorithm">算法库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../numeric.html" title="cpp/numeric">数值库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../io.html" title="cpp/io">输入/输出库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../locale.html" title="cpp/locale">本地化库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../regex.html" title="cpp/regex">正则表达式库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../atomic.html" title="cpp/atomic">原子操作库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../thread.html" title="cpp/thread">线程支持库</a> <span class="t-mark-rev t-since-cxx11">(C++11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../filesystem.html" title="cpp/filesystem">文件系统库</a> <span class="t-mark-rev t-since-cxx17">(C++17)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../experimental.html" title="cpp/experimental">技术规范</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../utility.html" title="cpp/utility">工具库</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../../types.html" title="cpp/types">类型支持</a>（基本类型、 RTTI 、类型特性）</td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../memory.html" title="cpp/memory">动态内存管理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../error.html" title="cpp/error">错误处理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../program.html" title="cpp/utility/program">程序工具</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../variadic.html" title="cpp/utility/variadic">变参数函数</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../feature_test.html" title="cpp/utility/feature test">库特性测试宏</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../../chrono.html" title="cpp/chrono">日期和时间</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../functional.html" title="cpp/utility/functional">函数对象</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../format.html" title="cpp/utility/format"> 格式化库</a> <span class="t-mark-rev t-since-cxx20">(C++20)</span> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../initializer_list.html" title="cpp/utility/initializer list"><span class="t-lines"><span>initializer_list</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../source_location.html" title="cpp/utility/source location"><span class="t-lines"><span>source_location</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../bitset.html" title="cpp/utility/bitset"><span class="t-lines"><span>bitset</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../hash.html" title="cpp/utility/hash"><span class="t-lines"><span>hash</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../integer_sequence.html" title="cpp/utility/integer sequence"><span class="t-lines"><span>integer_sequence</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx14">(C++14)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 关系运算符 <span class="t-mark-rev t-deprecated-cxx20">(C++20 中弃用)</span> </td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../rel_ops/operator_cmp.html" title="cpp/utility/rel ops/operator cmp"><span class="t-lines"><span>rel_ops::operator!=</span><span>rel_ops::operator&gt;</span><span>rel_ops::operator&lt;=</span><span>rel_ops::operator&gt;=</span></span></a></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 比较 <span class="t-mark-rev t-since-cxx20">(C++20)</span></td></tr><tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/three_way_comparable.html" title="cpp/utility/compare/three way comparable"><span class="t-lines"><span>three_way_comparable</span><span>three_way_comparable_with</span></span></a></div></div></td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/strong_ordering.html" title="cpp/utility/compare/strong ordering"><span class="t-lines"><span>strong_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/weak_ordering.html" title="cpp/utility/compare/weak ordering"><span class="t-lines"><span>weak_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/partial_ordering.html" title="cpp/utility/compare/partial ordering"><span class="t-lines"><span>partial_ordering</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/common_comparison_category.html" title="cpp/utility/compare/common comparison category"><span class="t-lines"><span>common_comparison_category</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_three_way_result.html" title="cpp/utility/compare/compare three way result"><span class="t-lines"><span>compare_three_way_result</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_three_way.html" title="cpp/utility/compare/compare three way"><span class="t-lines"><span>compare_three_way</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/strong_order.html" title="cpp/utility/compare/strong order"><span class="t-lines"><span>strong_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/weak_order.html" title="cpp/utility/compare/weak order"><span class="t-lines"><span>weak_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/partial_order.html" title="cpp/utility/compare/partial order"><span class="t-lines"><span>partial_order</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_strong_order_fallback.html" title="cpp/utility/compare/compare strong order fallback"><span class="t-lines"><span>compare_strong_order_fallback</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_weak_order_fallback.html" title="cpp/utility/compare/compare weak order fallback"><span class="t-lines"><span>compare_weak_order_fallback</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/compare_partial_order_fallback.html" title="cpp/utility/compare/compare partial order fallback"><span class="t-lines"><span>compare_partial_order_fallback</span></span></a></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../compare/named_comparison_functions.html" title="cpp/utility/compare/named comparison functions"><span class="t-lines"><span>is_eq</span><span>is_neq</span><span>is_lt</span><span>is_lteq</span><span>is_gt</span><span>is_gteq</span></span></a></div></div></td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 共用词汇类型</td></tr>
<tr class="t-nv-col-table"><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../pair.html" title="cpp/utility/pair"><span class="t-lines"><span>pair</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../tuple.html" title="cpp/utility/tuple"><span class="t-lines"><span>tuple</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../apply.html" title="cpp/utility/apply"><span class="t-lines"><span>apply</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../make_from_tuple.html" title="cpp/utility/make from tuple"><span class="t-lines"><span>make_from_tuple</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
</table></div></td><td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../optional.html" title="cpp/utility/optional"><span class="t-lines"><span>optional</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../any.html" title="cpp/utility/any"><span class="t-lines"><span>any</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../variant.html" title="cpp/utility/variant"><span class="t-lines"><span>variant</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"> <br>
</td></tr>
</table></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> swap 、 forward 与 move</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../../algorithm/swap.html" title="cpp/algorithm/swap"><span class="t-lines"><span>swap</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../exchange.html" title="cpp/utility/exchange"><span class="t-lines"><span>exchange</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx14">(C++14)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../forward.html" title="cpp/utility/forward"><span class="t-lines"><span>forward</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../move.html" title="cpp/utility/move"><span class="t-lines"><span>move</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../move_if_noexcept.html" title="cpp/utility/move if noexcept"><span class="t-lines"><span>move_if_noexcept</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 初等字符串转换</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../to_chars.html" title="cpp/utility/to chars"><span class="t-lines"><span>to_chars</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../from_chars.html" title="cpp/utility/from chars"><span class="t-lines"><span>from_chars</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../chars_format.html" title="cpp/utility/chars format"><span class="t-lines"><span>chars_format</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 类型运算</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../declval.html" title="cpp/utility/declval"><span class="t-lines"><span>declval</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../as_const.html" title="cpp/utility/as const"><span class="t-lines"><span>as_const</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="../launder.html" title="cpp/utility/launder"><span class="t-lines"><span>launder</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx17">(C++17)</span></span></span></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../format.html" title="cpp/utility/format"> 格式化库</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h2"><td colspan="5"> 格式化函数</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="format.html" title="cpp/utility/format/format"><span class="t-lines"><span>format</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="format_to.html" title="cpp/utility/format/format to"><span class="t-lines"><span>format_to</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="format_to_n.html" title="cpp/utility/format/format to n"><span class="t-lines"><span>format_to_n</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="formatted_size.html" title="cpp/utility/format/formatted size"><span class="t-lines"><span>formatted_size</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="vformat.html" title="cpp/utility/format/vformat"><span class="t-lines"><span>vformat</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="vformat_to.html" title="cpp/utility/format/vformat to"><span class="t-lines"><span>vformat_to</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 格式化器</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><strong class="selflink"><span class="t-lines"><span>formatter</span></span></strong></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="basic_format_parse_context.html" title="cpp/utility/format/basic format parse context"><span class="t-lines"><span>basic_format_parse_context</span><span>format_parse_context</span><span>wformat_parse_context</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="basic_format_context.html" title="cpp/utility/format/basic format context"><span class="t-lines"><span>basic_format_context</span><span>format_context</span><span>wformat_context</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 格式化参数</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="basic_format_arg.html" title="cpp/utility/format/basic format arg"><span class="t-lines"><span>basic_format_arg</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="basic_format_args.html" title="cpp/utility/format/basic format args"><span class="t-lines"><span>basic_format_args</span><span>format_args</span><span>wformat_args</span><span>format_args_t</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="visit_format_arg.html" title="cpp/utility/format/visit format arg"><span class="t-lines"><span>visit_format_arg</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="make_format_args.html" title="cpp/utility/format/make format args"><span class="t-lines"><span>make_format_args</span><span>make_wformat_args</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> 格式错误</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="format_error.html" title="cpp/utility/format/format error"><span class="t-lines"><span>format_error</span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div></td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<table class="t-dcl-begin"><tbody>
<tr class="t-dsc-header">
<td> <div>定义于头文件 <code><a href="../../header/format.html" title="cpp/header/format">&lt;format&gt;</a></code>
 </div></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl t-since-cxx20">
<td> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> T, <span class="kw1">class</span> CharT <span class="sy1">=</span> <span class="kw4">char</span><span class="sy1">&gt;</span><br>
<span class="kw1">struct</span> formatter<span class="sy4">;</span></span></div></td>
<td class="t-dcl-nopad">  </td>
<td> <span class="t-mark-rev t-since-cxx20">(C++20 起)</span> </td>
</tr>
<tr class="t-dcl-sep"><td></td><td></td><td></td></tr>
</tbody></table>
<p><code>formatter</code> 的被启用特化对给定类型定义格式化规则。被启用特化必须满足<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/named_req/Formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/named req/Formatter（页面不存在）"><i>格式化器</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(Formatter)</span> </a>要求。特别是，它们定义成员函数或函数模板 <code>parse</code> 与 <code>format</code> ，使得：
</p>
<ul><li> 成员 <code>parse</code> ……
</li></ul>
<dl><dd><ul><li> 接受单个 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">basic_format_parse_context</span><span class="sy1">&lt;</span>CharT<span class="sy1">&gt;</span></span></span> 类型参数 <code>pc</code>
</li><li> 分析范围 <code>[pc.begin(), pc.end())</code> 中的类型 <code>T</code> 的格式说明
</li><li> 存储分析出的格式声明符于 <code>*this</code>
</li><li> 返回表示格式说明结尾的 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">basic_format_parse_context</span><span class="sy1">&lt;</span>CharT<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">iterator</span></span></span> 类型值
</li><li> 可能抛出 <span class="t-lc">std::format_error</span> 以指示格式字符串中的错误
</li></ul>
</dd></dl>
<ul><li> 成员 <code>format</code> ……
</li></ul>
<dl><dd><ul><li> 接受二个参数： <code>T</code> 类型参数 <code>t</code> ，后随 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">basic_format_context</span><span class="sy1">&lt;</span>OutputIt, CharT<span class="sy1">&gt;</span></span></span> 类型参数 <code>fc</code> ，其中 <code>OutputIt</code> 是输出迭代器类型
</li><li> 按照 <code>*this</code> 中存储的说明符格式化 <code>t</code>
</li><li> 写输出到 <code>fc.out()</code>
</li><li> 返回表示输出结尾的 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">basic_format_context</span><span class="sy1">&lt;</span>OutputIt, CharT<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">iterator</span></span></span> 类型值
</li><li> 输出必须仅依赖 <code>t</code> 、 <code>fc.locale()</code> 及最后分析的格式说明符
</li></ul>
</dd></dl>
<p>被启用特化为<a href="../../named_req/DefaultConstructible.html" title="cpp/named req/DefaultConstructible"><i>可默认构造</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(DefaultConstructible)</span> </a>、<a href="../../named_req/CopyConstructible.html" title="cpp/named req/CopyConstructible"><i>可复制构造</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyConstructible)</span> </a>、<a href="../../named_req/CopyAssignable.html" title="cpp/named req/CopyAssignable"><i>可复制赋值</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyAssignable)</span> </a>、<a href="../../named_req/Swappable.html" title="cpp/named req/Swappable"><i>可交换</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(Swappable)</span> </a>且<a href="../../named_req/Destructible.html" title="cpp/named req/Destructible"><i>可析构</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(Destructible)</span> </a>。
</p><p>对每个未被库或用户提供被启用特化 <code>std::formatter&lt;T, CharT&gt;</code> 的类型 <code>T</code> 与 <code>CharT</code> ，该特化是完整类型且被禁用。被禁用特化不满足<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/named_req/Formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/named req/Formatter（页面不存在）"><i>格式化器</i> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(Formatter)</span> </a>要求，且 <span class="t-lc"><a href="../../types/is_default_constructible.html" title="cpp/types/is default constructible">std::is_default_constructible_v</a></span> 、 <span class="t-lc"><a href="../../types/is_copy_constructible.html" title="cpp/types/is copy constructible">std::is_copy_constructible_v</a></span> 、 <span class="t-lc"><a href="../../types/is_move_constructible.html" title="cpp/types/is move constructible">std::is_move_constructible_v</a></span> 、 <span class="t-lc"><a href="../../types/is_copy_assignable.html" title="cpp/types/is copy assignable">std::is_copy_assignable_v</a></span> 、 <span class="t-lc"><a href="../../types/is_move_assignable.html" title="cpp/types/is move assignable">std::is_move_assignable_v</a></span> 皆为 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">false</span></span></span> 。
</p>
<h3><span class="mw-headline" id=".E5.AF.B9.E5.9F.BA.E6.9C.AC.E7.B1.BB.E5.9E.8B.E5.92.8C.E5.AD.97.E7.AC.A6.E4.B8.B2.E7.B1.BB.E5.9E.8B.E7.9A.84.E6.A0.87.E5.87.86.E7.89.B9.E5.8C.96">对基本类型和字符串类型的标准特化</span></h3>
<p>以下列表中， <code>CharT</code> 为 <code>char</code> 或 <code>wchar_t</code> ， <code>ArithmeticT</code> 是任何 cv 无限定的算术类型，除了 <code>char</code> 、 <code>wchar_t</code> 、 <code>char8_t</code> 、 <code>char16_t</code> 或 <code>char32_t</code> 。
</p>
<table class="t-dcl-begin"><tbody>
<tr class="t-dcl">
<td class="t-dcl-nopad"> <div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">char</span>, <span class="kw4">char</span><span class="sy1">&gt;</span><span class="sy4">;</span><br>
<p><span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">char</span>, <span class="kw4">wchar_t</span><span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">wchar_t</span>, <span class="kw4">wchar_t</span><span class="sy1">&gt;</span><span class="sy4">;</span><br>
<br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span>CharT<span class="sy2">*</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">const</span> CharT<span class="sy2">*</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;</span><a href="../../types/size_t.html"><span class="kw100">std::<span class="me2">size_t</span></span></a> N<span class="sy1">&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">const</span> CharT<span class="br0">[</span>N<span class="br0">]</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> Traits, <span class="kw1">class</span> Alloc<span class="sy1">&gt;</span><br>
  <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><a href="../../string/basic_string.html"><span class="kw1228">std::<span class="me2">basic_string</span></span></a><span class="sy1">&lt;</span>CharT, Traits, Alloc<span class="sy1">&gt;</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> Traits<span class="sy1">&gt;</span><br>
  <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><a href="../../string/basic_string_view.html"><span class="kw1246">std::<span class="me2">basic_string_view</span></span></a><span class="sy1">&lt;</span>CharT, Traits<span class="sy1">&gt;</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span>ArithmeticT, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><a href="../../types/nullptr_t.html"><span class="kw102">std::<span class="me2">nullptr_t</span></span></a>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">void</span><span class="sy2">*</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span><br>
</p>
<span class="kw1">template</span><span class="sy1">&lt;&gt;</span> <span class="kw1">struct</span> formatter<span class="sy1">&lt;</span><span class="kw4">const</span> <span class="kw4">void</span><span class="sy2">*</span>, CharT<span class="sy1">&gt;</span><span class="sy4">;</span></span></div></td>
<td class="t-dcl-nopad">  </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl-sep"><td></td><td></td><td></td></tr>
</tbody></table>
<p>对其他指针和指向成员指针的格式化器被禁用。
</p><p>如 <code>std::formatter&lt;wchar_t, char&gt;</code> 和 <code>std::formatter&lt;const char*, wchar_t&gt;</code> 这些会要求编码转换的特化被禁用。
</p>
<h4><span class="mw-headline" id=".E6.A0.87.E5.87.86.E6.A0.BC.E5.BC.8F.E8.AF.B4.E6.98.8E">标准格式说明</span></h4>
<p>对于基本类型和字符串类型，格式说明基于 <a rel="nofollow" class="external text" href="https://docs.python.org/3/library/string.html#formatspec">Python 中的格式说明</a>。
</p><p>格式说明的语法是：
</p>
<table class="t-sdsc-begin">

<tr>
<td colspan="10" class="t-sdsc-sep">
</td></tr>
<tr class="t-sdsc">
<td class="t-sdsc-nopad"> <span class="t-spar">填充与对齐</span><span class="t-mark">(可选)</span> <span class="t-spar">符号</span><span class="t-mark">(可选)</span> <code><b>#</b></code><span class="t-mark">(可选)</span> <code><b>0</b></code><span class="t-mark">(可选)</span> <span class="t-spar">宽度</span><span class="t-mark">(可选)</span> <span class="t-spar">精度</span><span class="t-mark">(可选)</span> <code><b>L</b></code><span class="t-mark">(可选)</span> <span class="t-spar">类型</span><span class="t-mark">(可选)</span>
</td>
<td class="t-sdsc-nopad">
</td>
<td class="t-sdsc-nopad">
</td></tr>



<tr>
<td colspan="10" class="t-sdsc-sep">
</td></tr></table>
<p><span class="t-spar">符号</span> 、 <code><b>#</b></code> 及 <code><b>0</b></code> 选项仅当使用整数或浮点显示类型时合法。
</p>
<h5><span class="mw-headline" id=".E5.A1.AB.E5.85.85.E4.B8.8E.E5.AF.B9.E9.BD.90">填充与对齐</span></h5>
<p><span class="t-spar">填充与对齐</span> 是一个可选的<i>填充</i>字符（可为任何 <code><b>{</b></code> 或 <code><b>} </b></code> 外的的字符），后随<i>对齐</i>选项 <code><b>&lt;</b></code> 、 <code><b>&gt;</b></code> 、 <code><b>^</b></code> 之一。<i>对齐</i>选项的意义如下：
</p>
<ul><li> <code><b>&lt;</b></code> ：强制域对齐到可用空间起始。这在使用非整数非浮点显示类型时为默认。
</li><li> <code><b>&gt;</b></code> ：强制域对齐到可用空间末尾。这在使用整数或浮点显示类型时为默认。
</li><li> <code><b>^</b></code> ：强制域在可用空间中央，通过在值的前面插入 <span class="texhtml" style="white-space: nowrap;">⌊<span class="t-mfrac"><table><tr><td>n</td></tr><tr><td>2</td></tr></table></span>⌋</span> 个字符，后面插入 <span class="texhtml" style="white-space: nowrap;">⌈<span class="t-mfrac"><table><tr><td>n</td></tr><tr><td>2</td></tr></table></span>⌉</span> 个字符，其中 <span class="texhtml" style="white-space: nowrap;">n</span> 是待插入的总字符数。
</li></ul>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">char</span> c <span class="sy1">=</span> <span class="nu0">120</span><span class="sy4">;</span>
<span class="kw4">auto</span> s0 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:6}"</span>, <span class="nu0">42</span><span class="br0">)</span><span class="sy4">;</span>    <span class="co1">// s0 的值为 "    42"</span>
<span class="kw4">auto</span> s1 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:6}"</span>, <span class="st0">'x'</span><span class="br0">)</span><span class="sy4">;</span>   <span class="co1">// s1 的值为 "x     "</span>
<span class="kw4">auto</span> s2 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:*&lt;6}"</span>, <span class="st0">'x'</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s2 的值为 "x*****"</span>
<span class="kw4">auto</span> s3 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:*&gt;6}"</span>, <span class="st0">'x'</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s3 的值为 "*****x"</span>
<span class="kw4">auto</span> s4 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:*^6}"</span>, <span class="st0">'x'</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s4 的值为 "**x***"</span>
<span class="kw4">auto</span> s5 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:6d}"</span>, c<span class="br0">)</span><span class="sy4">;</span>    <span class="co1">// s5 的值为 "   120"</span>
<span class="kw4">auto</span> s6 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:6}"</span>, <span class="kw2">true</span><span class="br0">)</span><span class="sy4">;</span>  <span class="co1">// s6 的值为 "true  "</span></pre></div></div>
<h5><span class="mw-headline" id=".E7.AC.A6.E5.8F.B7.E3.80.81_.23_.E4.B8.8E_0">符号、 # 与 0</span></h5>
<p><span class="t-spar">符号</span> 选项能为下列之一：
</p>
<ul><li> <code><b>+</b></code> ：指示符号应该一同用于非负数和负数。在非负数的输出值前插入 <code>+</code> 号。
</li><li> <code><b>-</b></code> ：指示符号应该仅用于负数（这是默认行为）。
</li><li> 空格：指示应对非负数使用前导空格，而对负数使用负号。
</li></ul>
<p>负零被当作负数。
</p><p><span class="t-spar">符号</span> 选项应用于浮点无穷大和 NaN 。
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">double</span> inf <span class="sy1">=</span> <a href="../../types/numeric_limits.html"><span class="kw344">std::<span class="me2">numeric_limits</span></span></a><span class="sy1">&lt;</span><span class="kw4">double</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">infinity</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="kw4">double</span> nan <span class="sy1">=</span> <a href="../../types/numeric_limits.html"><span class="kw344">std::<span class="me2">numeric_limits</span></span></a><span class="sy1">&lt;</span><span class="kw4">double</span><span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">quiet_NaN</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<span class="kw4">auto</span> s0 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{0:},{0:+},{0:-},{0: }"</span>, <span class="nu0">1</span><span class="br0">)</span><span class="sy4">;</span>   <span class="co1">// s0 的值为 "1,+1,1, 1"</span>
<span class="kw4">auto</span> s1 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{0:},{0:+},{0:-},{0: }"</span>, <span class="sy2">-</span><span class="nu0">1</span><span class="br0">)</span><span class="sy4">;</span>  <span class="co1">// s1 的值为 "-1,-1,-1,-1"</span>
<span class="kw4">auto</span> s2 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{0:},{0:+},{0:-},{0: }"</span>, inf<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s2 的值为 "inf,+inf,inf, inf"</span>
<span class="kw4">auto</span> s3 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{0:},{0:+},{0:-},{0: }"</span>, nan<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s3 的值为 "nan,+nan,nan, nan"</span></pre></div></div>
<p><code><b>#</b></code> 选项导致将<i>替用形式</i>用于转换。
</p>
<ul><li> 对于整数类型，使用二进制、八进制或十六进制显示类型时，替用形式插入前缀（ <code>0b</code> 、 <code>0</code> 或 <code>0x</code> ）到输出值中，若有符号则于符号（可为空格）前，否则于输出值前。
</li><li> 对于浮点类型，替用形式导致有限值的转换结果始终含有小数点字符，即使其后无数位。正常情况下，小数点字符仅若有数位后随它才出现于转换结果。另外，对于 <code><b>g</b></code> 与 <code><b>G</b></code> 转换，不从结果移除尾随的零。
</li></ul>
<p><code><b>0</b></code> 选项以前导零填充域（后随任何符号或底）到域宽，除了应用到无穷大或 NaN 时。若 <code>0</code> 字符与<i>对齐</i>选项一同出现，则忽略 <code>0</code> 字符。
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="kw4">char</span> c <span class="sy1">=</span> <span class="nu0">120</span><span class="sy4">;</span>
<span class="kw4">auto</span> s1 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:+06d}"</span>, c<span class="br0">)</span><span class="sy4">;</span>   <span class="co1">// s1 的值为 "+00120"</span>
<span class="kw4">auto</span> s2 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:#06x}"</span>, <span class="nu12">0xa</span><span class="br0">)</span><span class="sy4">;</span> <span class="co1">// s2 的值为 "0x000a"</span>
<span class="kw4">auto</span> s3 <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:&lt;06}"</span>, <span class="sy2">-</span><span class="nu0">42</span><span class="br0">)</span><span class="sy4">;</span>  <span class="co1">// s3 的值为 "-42   " （因 &lt; 对齐忽略 0 ）</span></pre></div></div>
<h5><span class="mw-headline" id=".E5.AE.BD.E5.BA.A6.E4.B8.8E.E7.B2.BE.E5.BA.A6">宽度与精度</span></h5>
<p><span class="t-spar">宽度</span> 为正十进制数，或嵌套的替换域（ <code><b>{} </b></code> 或  <code><b>{</b></code><i>n</i><code><b>} </b></code> ）。宽度若存在则指定最小域宽。
</p><p><span class="t-spar">精度</span> 为点（ <code><b>.</b></code> ）后随非负十进制数或嵌套的替换域。此域指示精度或最大域大小。它仅能用于浮点与字符串类型。对于浮点类型，此域指定格式化精度。对于字符串类型，它指定将从字符串使用多少字符。
</p><p>若 <span class="t-spar">宽度</span> 或 <span class="t-spar">精度</span> 中使用嵌套的替换域，而对应的参数不是整数类型，或为负，或对于 <span class="t-spar">宽度</span> 为零，则抛出 <span class="t-lc">std::format_error</span> 类型异常。
</p>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style=""><tr><td class="mbox-empty-cell"></td><td class="mbox-text" style="">本节未完成<br>原因：小示例 </td></tr></table>
<h5><span class="mw-headline" id="L_.EF.BC.88.E6.9C.AC.E5.9C.B0.E7.8E.AF.E5.A2.83.E7.89.B9.E5.AE.9A.E7.9A.84.E6.A0.BC.E5.BC.8F.E5.8C.96.EF.BC.89">L （本地环境特定的格式化）</span></h5>
<p><code><b>L</b></code> 选项导致使用本地环境特定的形式。此选项仅对算术类型合法。
</p>
<ul><li> 对于整数类型，本地环境特定形式按照环境的本地环境，插入适合的数位组分隔字符。
</li><li> 对于浮点类型，本地环境特定形式按照环境的本地环境，插入适合的数位组和底分隔字符。
</li><li> 对于 <code>bool</code> 的文本表示，本地环境特定形式使用如同通过 <span class="t-lc"><a href="../../locale/numpunct/truefalsename.html" title="cpp/locale/numpunct/truefalsename">std::numpunct::truename</a></span> 或 <span class="t-lc">std::numpunct​::​falsename</span> 获得的字符串。
</li></ul>
<h5><span class="mw-headline" id=".E7.B1.BB.E5.9E.8B">类型</span></h5>
<p><span class="t-spar">类型</span> 选项确定应该如何显示数据。
</p><p>可用的字符串显示类型为：
</p>
<ul><li> 无、 <code><b>s</b></code> ：复制字符串到输出。
</li></ul>
<p>可用的 <code>char</code> 、 <code>wchar_t</code> 与 <code>bool</code> 外的整数类型的整数显示类型为：
</p>
<ul><li> <code><b>b</b></code> ：二进制格式。如同通过调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">to_chars</span><span class="br0">(</span>first, last, value, <span class="nu0">2</span><span class="br0">)</span></span></span> 产生输出。底前缀为 <code>0b</code> 。
</li><li> <code><b>B</b></code> ：同 <code><b>b</b></code> ，除了底前缀为 <code>0B</code> 。
</li><li> <code><b>c</b></code> ：复制字符 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw1">static_cast</span><span class="sy1">&lt;</span>CharT<span class="sy1">&gt;</span><span class="br0">(</span>value<span class="br0">)</span></span></span> 到输出，其中 <span class="t-c"><span class="mw-geshi cpp source-cpp">CharT</span></span> 是格式字符串的字符类型。若值不在 <span class="t-c"><span class="mw-geshi cpp source-cpp">CharT</span></span> 的可表示值的范围中则抛出 <span class="t-lc">std::format_error</span> 。
</li><li> <code><b>d</b></code> ：十进制格式。如同通过调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">to_chars</span><span class="br0">(</span>first, last, value<span class="br0">)</span></span></span> 产生输出。
</li><li> <code><b>o</b></code> ：八进制格式。如同通过调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">to_chars</span><span class="br0">(</span>first, last, value, <span class="nu0">8</span><span class="br0">)</span></span></span>.产生输出。若对应参数值非零则底前缀为 <code>0</code> ，否则为空。
</li><li> <code><b>x</b></code> ：十六进制格式。如同通过调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">to_chars</span><span class="br0">(</span>first, last, value, <span class="nu0">16</span><span class="br0">)</span></span></span> 产生输。底前缀为 <code>0x</code> 。
</li><li> <code><b>X</b></code> ：同 <code><b>x</b></code> ，除了对 9 以上的数字使用大写字母且底前缀为 <code>0X</code> 。
</li><li> 无：同 <code><b>d</b></code> 。
</li></ul>
<p>可用的 <code>char</code> 及 <code>wchar_t</code> 表示类型为：
</p>
<ul><li> 无、 <code><b>c</b></code> ：复制字符到输出。
</li><li> <code><b>b</b></code> 、 <code><b>B</b></code> 、 <code><b>d</b></code> 、 <code><b>o</b></code> 、 <code><b>x</b></code> 、 <code><b>X</b></code> ：使用整数表示类型。
</li></ul>
<p>可用的 <code>bool</code> 表示类型为：
</p>
<ul><li> 无、 <code><b>s</b></code> ：复制文本表示（ <code><b>true</b></code> 或 <code><b>false</b></code> 或本地环境特定形式）到输出。
</li><li> <code><b>b</b></code> 、 <code><b>B</b></code> 、 <code><b>c</b></code> 、 <code><b>d</b></code> 、 <code><b>o</b></code> 、 <code><b>x</b></code> 、 <code><b>X</b></code> ：以值 <code>static_cast&lt;unsigned char&gt;(value)</code> 使用整数表示类型。
</li></ul>
<p>可用的浮点表示类型为：
</p>
<ul><li> <code><b>a</b></code> ：若指定<i>精度</i>，则如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::hex, precision)</tt></a> 产生输出，其中 <code>precision</code> 是指定的精度，否则如同通过 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::hex)</tt></a> 产生输出。
</li><li> <code><b>A</b></code> ：同 <code><b>a</b></code> ，除了对 9 以上的数字使用大写字母并用 <code>P</code> 指示指数。
</li><li> <code><b>e</b></code> ：如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::scientific, precision)</tt></a> 产生输出，其中 <code>precision</code> 为指定的精度，或若未指定精度则为 6 。
</li><li> <code><b>E</b></code> ：同 <code><b>e</b></code> ，除了用 <code>E</code> 指示指数。
</li><li> <code><b>f</b></code> 、 <code><b>F</b></code> ：如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::fixed, precision)</tt></a> 产生输出，其中 <code>precision</code> 为指定的精度，或若未指定精度则为 6 。
</li><li> <code><b>g</b></code> ：如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::general, precision)</tt></a> 产生输出，其中 <code>precision</code> 为指定的精度，或若未指定精度则为 6 。
</li><li> <code><b>G</b></code> ：同 <code><b>g</b></code> ，除了用 <code>E</code> 指示指数。
</li><li> 无：若指定<i>精度</i>，则如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value, std::chars_format::general, precision)</tt></a> 产生输出，其中 <code>precision</code> 为指定的精度；否则如同通过调用 <a href="../to_chars.html" title="cpp/utility/to chars"><tt>std::to_chars(first, last, value)</tt></a> 产生输出。
</li></ul>
<p>对于小写表示类型，分别格式化无穷大和 NaN 为 <code>inf</code> 与 <code>nan</code> 。对于大写表示类型，分别格式化无穷大和 NaN 为 <code>INF</code> 与 <code>NAN</code> 。
</p><p>可用的指针表示类型（亦用于 <code>std::nullptr_t</code> ）为：
</p>
<ul><li> 无、 <code><b>p</b></code> ：若定义 <span class="t-lc"><a href="../../types/integer.html" title="cpp/types/integer">std::uintptr_t</a></span> ，则如同通过调用 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">to_chars</span><span class="br0">(</span>first, last, <span class="kw1">reinterpret_cast</span><span class="sy1">&lt;</span><a href="../../types/integer.html"><span class="kw133">std::<span class="me2">uintptr_t</span></span></a><span class="sy1">&gt;</span><span class="br0">(</span>value<span class="br0">)</span>, <span class="nu0">16</span><span class="br0">)</span></span></span> 产生输出，并添加前缀 <code>0x</code> 到输出；否则输出为实现定义。
</li></ul>
<h3><span class="mw-headline" id=".E5.BA.93.E7.B1.BB.E5.9E.8B.E7.9A.84.E6.A0.87.E5.87.86.E7.89.B9.E5.8C.96">库类型的标准特化</span></h3>
<table class="t-dsc-begin">

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/duration/formatter.html" title="cpp/chrono/duration/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::duration&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按提供的格式格式化 <code>duration</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/system_clock/formatter.html" title="cpp/chrono/system clock/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::sys_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>sys_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/utc_clock/formatter.html" title="cpp/chrono/utc clock/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::utc_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>utc_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/tai_clock/formatter.html" title="cpp/chrono/tai clock/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::tai_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>tai_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/gps_clock/formatter.html" title="cpp/chrono/gps clock/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::gps_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>gps_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/file_clock/formatter.html" title="cpp/chrono/file clock/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::file_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>file_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/local_t/formatter.html" title="cpp/chrono/local t/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::local_time&gt;</span></span></span></a></div><div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>local_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/day/formatter.html" title="cpp/chrono/day/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::day&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>day</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/month/formatter.html" title="cpp/chrono/month/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::month&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>month</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/year/formatter.html" title="cpp/chrono/year/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/weekday/formatter.html" title="cpp/chrono/weekday/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::weekday&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>weekday</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/weekday_indexed/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/weekday indexed/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::weekday_indexed&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>weekday_indexed</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/weekday_last/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/weekday last/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::weekday_last&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>weekday_last</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/month_day/formatter.html" title="cpp/chrono/month day/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::month_day&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>month_day</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/month_day_last/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/month day last/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::month_day_last&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>month_day_last</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/month_weekday/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/month weekday/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::month_weekday&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>month_weekday</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/month_weekday_last/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/month weekday last/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::month_weekday_last&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>month_weekday_last</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/year_month/formatter.html" title="cpp/chrono/year month/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year_month&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year_month</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/year_month_day/formatter.html" title="cpp/chrono/year month day/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year_month_day&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year_month_day</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/year_month_day_last/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/year month day last/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year_month_day_last&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year_month_day_last</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/year_month_weekday/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/year month weekday/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year_month_weekday&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year_month_weekday</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/year_month_weekday_last/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/year month weekday last/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::year_month_weekday_last&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>year_month_weekday_last</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/hh_mm_ss/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/hh mm ss/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::hh_mm_ss&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>hh_mm_ss</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/sys_info/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/sys info/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::sys_info&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>sys_info</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/chrono/local_info/formatter&amp;action=edit&amp;redlink=1" class="new" title="cpp/chrono/local info/formatter（页面不存在）"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::local_info&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>local_info</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>

<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="../../chrono/zoned_time/formatter.html" title="cpp/chrono/zoned time/formatter"> <span class="t-lines"><span>std::formatter<span class="t-dsc-small">&lt;std::chrono::zoned_time&gt;</span></span></span></a></div></div>
</td>
<td>   <span class="t-lc">std::formatter</span> 的特化，按照提供的格式格式化 <code>zoned_time</code>  <br> <span class="t-mark">(类模板特化)</span> </td></tr>
</table>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">示例</span></h3>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="cpp source-cpp"><pre class="de1"><span class="co2">#include &lt;format&gt;</span>
<span class="co2">#include &lt;iostream&gt;</span>
 
<span class="co1">// 类型 T 的包装</span>
<span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> T<span class="sy1">&gt;</span>
<span class="kw1">struct</span> Box <span class="br0">{</span>
    T value<span class="sy4">;</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="co1">// 能用被包装值的格式说明格式化包装 Box&lt;T&gt;</span>
<span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> T, <span class="kw1">class</span> CharT<span class="sy1">&gt;</span>
<span class="kw1">struct</span> std<span class="sy4">::</span><span class="me2">formatter</span><span class="sy1">&lt;</span>Box<span class="sy1">&lt;</span>T<span class="sy1">&gt;</span>, CharT<span class="sy1">&gt;</span> <span class="sy4">:</span> std<span class="sy4">::</span><span class="me2">formatter</span><span class="sy1">&lt;</span>T, CharT<span class="sy1">&gt;</span> <span class="br0">{</span>
    <span class="co1">// 从基类继承 parse()</span>
 
    <span class="co1">// 通过以被包装值调用基类实现定义 format()</span>
    <span class="kw1">template</span><span class="sy1">&lt;</span><span class="kw1">class</span> FormatContext<span class="sy1">&gt;</span>
    <span class="kw4">auto</span> format<span class="br0">(</span>Box<span class="sy1">&lt;</span>T<span class="sy1">&gt;</span> t, FormatContext<span class="sy3">&amp;</span> fc<span class="br0">)</span> <span class="br0">{</span>
        <span class="kw1">return</span> std<span class="sy4">::</span><span class="me2">formatter</span><span class="sy1">&lt;</span>T, CharT<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span>t.<span class="me1">value</span>, fc<span class="br0">)</span><span class="sy4">;</span>
    <span class="br0">}</span>
<span class="br0">}</span><span class="sy4">;</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
    Box<span class="sy1">&lt;</span><span class="kw4">int</span><span class="sy1">&gt;</span> v <span class="sy1">=</span> <span class="br0">{</span> <span class="nu0">42</span> <span class="br0">}</span><span class="sy4">;</span>
    <a href="../../io/cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> std<span class="sy4">::</span><span class="me2">format</span><span class="br0">(</span><span class="st0">"{:#x}"</span>, v<span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">0x2a</pre></div></div> 
</div>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>

<!-- 
NewPP limit report
Preprocessor visited node count: 11195/1000000
Preprocessor generated node count: 18796/1000000
Post‐expand include size: 324086/2097152 bytes
Template argument size: 74397/2097152 bytes
Highest expansion depth: 23/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_zh_:pcache:idhash:12412-0!*!0!!zh!*!zh!* and timestamp 20200312151746 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    来自“<a href="https://zh.cppreference.com/mwiki/index.php?title=cpp/utility/format/formatter&amp;oldid=65265">https://zh.cppreference.com/mwiki/index.php?title=cpp/utility/format/formatter&amp;oldid=65265</a>”                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>导航</h5>
            <ul><li><a href="https://zh.cppreference.com/w/cpp/utility/format/formatter">Online version</a></li><li>Offline version retrieved 2020-03-14 18:00.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> 本页面最后修改于2020年3月10日 (星期二) 07:11。</li>
                                    <li id="footer-info-viewcount">此页面已被浏览过309次。</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.MathJax","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 2.391 secs. -->
	</body>
<!-- Cached 20200312151746 -->
</html>